package com.atguigu.daijia.customer.controller;

import com.atguigu.daijia.common.constant.DaiJiaCommonConstants;
import com.atguigu.daijia.common.constant.RedisConstant;
import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.login.GuiguLogin;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.common.util.AuthContextHolder;
import com.atguigu.daijia.customer.client.CustomerInfoFeignClient;
import com.atguigu.daijia.customer.service.CustomerService;
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "客户API接口管理")
@RestController
@RequestMapping("/customer")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CustomerController {

    @Resource
    private CustomerService customerService;

    @GuiguLogin
    @Operation(summary = "获取客户登录信息")
    @GetMapping("/getCustomerLoginInfo")
    public Result<CustomerLoginVo> getCustomerLoginInfo() {
        return Result.ok(customerService.getCustomerLoginInfo(AuthContextHolder.getUserId()));
    }

    /**
     未加入登录校验aop前
     @Operation(summary = "获取客户登录信息")
     @GetMapping("/getCustomerLoginInfo")
     public Result<CustomerLoginVo> getCustomerLoginInfo(@RequestHeader(value = DaiJiaCommonConstants.TOKEN_STR) String token) {
     return Result.ok(customerService.getCustomerLoginInfo(token));
     }

     */

    @Operation(summary = "小程序授权登录")
    @GetMapping("/login/{code}")
    public Result<String> wxLogin(@PathVariable String code) {
        return Result.ok(customerService.login(code));
    }

    @Operation(summary = "更新客户微信手机号码")
    @PostMapping("/updateWxPhone")
    public Result<Boolean> updateWxPhoneNumber(@RequestBody UpdateWxPhoneForm form) {
        return Result.ok(customerService.updateWxPhoneNumber(form));
    }

}

